﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LotteryAdmin.AdminService;
using System.Threading;

namespace LotteryAdmin
{
    public partial class ChildAddLotteryNums : ChildWindow
    {
        AdminService.LotteryAdminClient client = WcfProxy.GetProxy;
        LotteryNumsInfo Info;
        public ChildAddLotteryNums()
        {
            InitializeComponent();
            client.GetCurrenIssuNoCompleted += new EventHandler<AdminService.GetCurrenIssuNoCompletedEventArgs>(client_GetCurrenIssuNoCompleted);
            client.GetCurrenIssuNoAsync((cbxLotteryType.SelectedIndex + 1).ToString());
            client.SetLotteryNumsInfoCompleted += new EventHandler<SetLotteryNumsInfoCompletedEventArgs>(client_SetLotteryNumsInfoCompleted);
            client.UpdateLotteryNumsCompleted += new EventHandler<UpdateLotteryNumsCompletedEventArgs>(client_UpdateLotteryNumsCompleted);
        }

        private void client_SetLotteryNumsInfoCompleted(object sender, SetLotteryNumsInfoCompletedEventArgs e)
        {
            Info = e.Result;
            Info.LotteryNums = txtLotteryNums.Text.Trim();
            Info.UpdateUser = "ManualCollect";
            Info.UpdateTime = System.DateTime.Now;
            client.UpdateLotteryNumsAsync(Info);
        }

        private void client_UpdateLotteryNumsCompleted(object sender, UpdateLotteryNumsCompletedEventArgs e)
        {
            MessageBox.Show("新增开奖号码成功,后台已经在自动派奖！");
            this.Close();
        }

        private void client_GetCurrenIssuNoCompleted(object sender, AdminService.GetCurrenIssuNoCompletedEventArgs e)
        {
            txtbIssueNo.Text = e.Result.Trim('\'');
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            client.SetLotteryNumsInfoAsync(cbxLotteryType.SelectedIndex + 1);
        }

        private void cbxLotteryType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (e.RemovedItems.Count > 0)
            {
                client.GetCurrenIssuNoAsync((cbxLotteryType.SelectedIndex + 1).ToString());
            }
        }
    }
}

